﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body onload="Puppi.MyFunc();">
<p>Select device: <device type="audio_capture" id="media_device"></p>
 
<input type="button" id="record_ctl_but" value="Record" disabled></input>
<script type="text/javascript">

    var Puppi = {}
    Puppi.MyFunc = function() {
        // in window.onload
        document.getElementById("media_device").onchange = function () {
            // ready to record
            audioStream = this.data;
            recordCtlBut.disabled = false;
        };
        recordCtlBut = document.getElementById("record_ctl_but");

        recordCtlBut.onclick = function () {
            if (!recorder) {
                // start recording
                recordCtlBut.value = "Stop";
                recorder = audioStream.record();
                // set the maximum audio clip length to 10 seconds
                recordTimer = setTimeout(stopRecording, 10000);
            } else
                stopRecording();
        };
    }
    function stopRecording() {
        clearTimeout(recordTimer);
        var audioFile = recorder.stop();
        useAudioFile(audioFile);

        // reset to allow new recording session
        recorder = null;
        recordCtlBut.value = "Record";
    }
</script>

</body>

</html>
